'''
Created on Nov 19, 2010

@author: namikata
'''

import pygame
from pygame.locals import *

class Keyboard(object):
    '''
    classdocs
    '''

    last_pressed = ()
    last_pressed_mod = ()
    current_pressed = ()
    current_pressed_mod = ()
    
    def get_pressed_key(self,key):
        """0 = not pressed, 1 = pressed, 2 = hold """
        if self.current_pressed[key]:
            return int(self.current_pressed[key]) + int(self.last_pressed[key])
        else:
            0
    
    def get_pressed_mod(self,key):
        return self.current_pressed_mod & key
    
    def get_hold_mod(self,key):
        return self.get_pressed_mod(key) and self.last_pressed_mod & key 
    
    def update(self,pressed_keys, mod_keys):
        self.last_pressed = self.current_pressed
        self.last_pressed_mod = self.current_pressed_mod
        self.current_pressed = pressed_keys
        self.current_pressed_mod = mod_keys